package com.diaosidadui;

public class jointArray {
    public static void main(String[] args) {
        /*
        定义一个数组{1,2,3},定义一个方法,调用方法输出结果[1,2,3]



         */
        int[] arr = {1, 2, 3};
        char[] char1 = {'1', '2', '3', 'a', 'b', 'c'};

        System.out.println(printArray(arr));
        System.out.println(printArray(char1));

    }

    public static String printArray(int[] arr) {
        StringBuilder s = new StringBuilder("[ ");
        for (int i = 0; i < arr.length; i++) {
            if (i < arr.length - 1) {
                s.append(arr[i] + " , ");
            } else {
                s.append(arr[i]).append(" ]");
            }

        }
        return s.toString();
    }

    public static String printArray(char[] arr) {
        StringBuilder s = new StringBuilder("[ ");
        for (int i = 0; i < arr.length; i++) {
            if (i < arr.length - 1) {
                s.append(arr[i] + " , ");
            } else {
                s.append(arr[i]).append(" ]");
            }

        }
        return s.toString();
    }

}
